package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Return implements Ioperation{

    @Override
    public void work(BookList bookList) {
        Scanner in = new Scanner(System.in);
        System.out.println("输入要归还的图书名：");
        String name = in.nextLine();
        for(int i = 0; i < bookList.getUsedSize(); i++){
            Book book = bookList.getBooks()[i];
            if(name.equals(book.getName())) {
                if (book.isBorrowed()) {
                    book.setBorrowed(false);
                    System.out.println("归还成功");
                    return;
                } else {
                    System.out.println("图书未借阅");
                    return;
                }
            }
        }
        System.out.println("图书不存在");
    }
}
